//***************************************************************************
//*
//*	File:			DialogFilters.cpp
//*	Description:	Filters dialog
//*
//***************************************************************************

//
//--------------------------------------------------------------- PRECOMPILED
//

#include "stdafx.h"

//
//--------------------------------------------------- DECLARATION DEPENDENCIES
//

#include "SmartReplace.h"

//
//--------------------------------------------------------------- DECLARATION
//

#include "DialogFilters.h"

//
//--------------------------------------------------- DEFINITION DEPENDENCIES
//

#include "StringEx.h"
#include "DialogOptions.h"
#include "DialogFolder.h"
#include <afxdlgs.h>

//
//-------------------------------------------------------------- PREPROCESSOR
//

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
//---------------------------------------------------------------- DEFINITION
//

//
//---------------------------------------------------------------------------------------------------
//*************************************     CON/DESTRUCTION     *************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					  Constructor
//***************************************************************************************************
//**	@DOC		CONSTRUCTION
//**	@MFUNC		Default constructor
//**	@PARM		[in|opt] Pointer to the parent window
//**	@END
//***************************************************************************************************
//inline
CDialogFilters::CDialogFilters( CWnd* pParent /*=NULL*/ )
: CDialog( CDialogFilters::IDD, pParent )
{
	//{{AFX_DATA_INIT(CDialogFilters)
	//}}AFX_DATA_INIT
}

//
//---------------------------------------------------------------------------------------------------
//*****************************************     GET/SET     *****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																					   GetFolders  
//***************************************************************************************************
//**	@DOC		GET
//**	@MFUNC		Returns the displayed folders
//**	@PARM		[out] The array of folders
//**	@COMM		Does not clear the array in davance
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::GetFolders( CDialogSmartReplace::CFolderArray& a_arrFolders ) const 
{
	for ( int iFolder = 0; iFolder < this->m_arrFolders.GetSize(); iFolder++ )
	{
		if ( this->m_arrFolders[ iFolder ].m_strPath == "(double-click to edit)" )
		{
			continue;
		}

		a_arrFolders.Add( this->m_arrFolders[ iFolder ] );
	}
}

//***************************************************************************************************
//**																					 GetFileMasks
//***************************************************************************************************
//**	@DOC		GET
//**	@MFUNC		Returns the displayed file maks
//**	@PARM		[out] The array of file masks
//**	@COMM		Does not clear the array in davance
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::GetFileMasks( CDialogSmartReplace::CFileMaskArray& a_arrFileMasks ) const 
{
	for ( int iFileMask = 0; iFileMask < this->m_arrFileMasks.GetSize(); iFileMask++ )
	{
		if ( this->m_arrFileMasks[ iFileMask ].m_strMask == "(click to edit)" )
		{
			continue;
		}

		a_arrFileMasks.Add( this->m_arrFileMasks[ iFileMask ] );
	}
}

//***************************************************************************************************
//**																					   SetFolders
//***************************************************************************************************
//**	@DOC		SET
//**	@MFUNC		Sets the folders to display
//**	@PARM		[in] The array of folders
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::SetFolders( const CDialogSmartReplace::CFolderArray& a_arrFolders ) 
{
	this->m_arrFolders.RemoveAll();

	for ( int iFolder = 0; iFolder < a_arrFolders.GetSize(); iFolder++ )
	{
		this->m_arrFolders.Add( a_arrFolders[ iFolder ] );
	}
}

//***************************************************************************************************
//**																					 SetFileMasks 
//***************************************************************************************************
//**	@DOC		SET
//**	@MFUNC		Sets the file masks to display
//**	@PARM		[in] The array of file masks
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::SetFileMasks( const CDialogSmartReplace::CFileMaskArray& a_arrFileMasks ) 
{
	this->m_arrFileMasks.RemoveAll();

	for ( int iFileMask = 0; iFileMask < a_arrFileMasks.GetSize(); iFileMask++ )
	{
		this->m_arrFileMasks.Add( a_arrFileMasks[ iFileMask ] );
	}
}

//
//---------------------------------------------------------------------------------------------------
//*****************************************     HELPERS     *****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																						GetFolder
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Determines the folder at the specified index
//**	@PARM		[in] The index
//**	@PARM		[out] The folder
//**	@RDESC		<t TRUE> if successful, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CDialogFilters::GetFolder( int a_iIndex, CFolder& a_Folder ) const 
{
	a_Folder.m_strPath	= this->m_ctrlListFolders.GetItemText( a_iIndex, 0 );
	a_Folder.m_bRecurse = this->m_ctrlListFolders.GetItemText( a_iIndex, 1 ) == "Yes" ? TRUE : FALSE;
	a_Folder.m_bEnabled = this->m_ctrlListFolders.GetCheck	 ( a_iIndex );

	return TRUE;
}

//***************************************************************************************************
//**																					  GetFileMask
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Determines the file mask at the specified index
//**	@PARM		[in] The index
//**	@PARM		[out] The file mask
//**	@RDESC		<t TRUE> if successful, <t FALSE> otherwise.
//**	@END
//***************************************************************************************************
//inline
BOOL CDialogFilters::GetFileMask( int a_iIndex, CFileMask& a_FileMask ) const 
{
	a_FileMask.m_strMask	= this->m_ctrlListFileMasks.GetItemText	( a_iIndex, 0 );
	a_FileMask.m_bEnabled	= this->m_ctrlListFileMasks.GetCheck	( a_iIndex );

	return TRUE;
}

//***************************************************************************************************
//**																					 InsertFolder
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Inserts the specified folder at the specified index
//**	@PARM		[in] The index
//**	@PARM		[in] The folder
//**	@RDESC		The item's index
//**	@END
//***************************************************************************************************
//inline
int CDialogFilters::InsertFolder( int a_iIndex, const CFolder& a_Folder ) 
{
	int iItem = a_iIndex;
		iItem = this->m_ctrlListFolders.InsertItem( iItem, "" );

	this->m_ctrlListFolders.SetItemText	( iItem, 0,	a_Folder.m_strPath	);
	this->m_ctrlListFolders.SetItemText	( iItem, 1,	a_Folder.m_bRecurse ? "Yes" : "No" );
	this->m_ctrlListFolders.SetCheck	( iItem,	a_Folder.m_bEnabled );

	return iItem;
}

//***************************************************************************************************
//**																				   InsertFileMask
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Inserts the specified file mask at the specified index
//**	@PARM		[in] The index
//**	@PARM		[in] The file mask
//**	@RDESC		The item's index
//**	@END
//***************************************************************************************************
//inline
int CDialogFilters::InsertFileMask( int a_iIndex, const CFileMask& a_FileMask ) 
{
	int iItem = a_iIndex;
		iItem = this->m_ctrlListFileMasks.InsertItem( iItem, "" );

	this->m_ctrlListFileMasks.SetItemText	( iItem, 0,	a_FileMask.m_strMask	);
	this->m_ctrlListFileMasks.SetCheck		( iItem,	a_FileMask.m_bEnabled	);

	return iItem;
}

//***************************************************************************************************
//**																				    ExportFilters 
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Exports filters to the specified file
//**	@PARM		[in] The file's path
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::ExportFilters( const CString& a_strFile ) 
{
	//
	//	OPEN FILE
	//
	CStdioFile file;
	
	if ( TRUE == file.Open( a_strFile, CFile::modeWrite | CFile::typeText ) )
	{
		//
		//	APPEND
		//
		file.SeekToEnd();
	}
	else 
	{
		file.Open( a_strFile, CFile::modeCreate | CFile::modeWrite | CFile::typeText );
	}

	//
	//	WRITE FOLDERS
	//
	CFolder folder	;
	CString strKey	;

	file.WriteString( "[Folders]\n\n" );

	strKey.Format( "Folder.Count=%d\n\n", this->m_ctrlListFolders.GetItemCount() ); file.WriteString( strKey );

	for ( int iFolder = 0; iFolder < this->m_ctrlListFolders.GetItemCount(); iFolder++ )
	{
		this->GetFolder( iFolder, folder );

		strKey.Format( "Folder.Path.%d="	, iFolder );	file.WriteString( strKey + folder.m_strPath	 + "\n" );
		strKey.Format( "Folder.Recurse.%d="	, iFolder );	file.WriteString( strKey + ( folder.m_bRecurse ? CString( "true" ) : CString( "false" ) ) + "\n" );
		strKey.Format( "Folder.Enabled.%d="	, iFolder );	file.WriteString( strKey + ( folder.m_bEnabled ? CString( "true" ) : CString( "false" ) ) + "\n\n" );
	}

	//
	//	WRITE FILE MASKS
	//
	CFileMask mask	;

	file.WriteString( "[FileMasks]\n\n" );

	strKey.Format( "FileMask.Count=%d\n\n", this->m_ctrlListFileMasks.GetItemCount() ); file.WriteString( strKey );

	for ( int iFileMask = 0; iFileMask < this->m_ctrlListFileMasks.GetItemCount(); iFileMask++ )
	{
		this->GetFileMask( iFileMask, mask );

		strKey.Format( "FileMask.Mask.%d="		, iFileMask );	file.WriteString( strKey + mask.m_strMask	 + "\n" );
		strKey.Format( "FileMask.Enabled.%d="	, iFileMask );	file.WriteString( strKey + ( mask.m_bEnabled ? CString( "true" ) : CString( "false" ) ) + "\n\n" );
	}

	//
	//	CLOSE FILE
	//
	file.Close();
}

//***************************************************************************************************
//**																				    ImportFilters 
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Imports filters from the specified file
//**	@PARM		[in] The file's path
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::ImportFilters( const CString& a_strFile ) 
{
	//
	//	OPEN FILE
	//
	CStdioFile file( a_strFile, CFile::modeRead | CFile::typeText );

	//
	//	FIND COUNTS
	//
	CString		strLine		;
	int			iFolders	= -1;
	int			iFileMasks	= -1;

	while ( TRUE == file.ReadString( strLine ) )
	{
		//
		//	PARSE LINE
		//
		if ( strLine.Find( "Folder.Count" ) >= 0 )
		{
			::sscanf( strLine, "Folder.Count=%d", &iFolders );

			if ( iFileMasks >= 0 )
			{
				break;
			}
			else
			{
				continue;
			}
		}

		if ( strLine.Find( "FileMask.Count" ) >= 0 )
		{
			::sscanf( strLine, "FileMask.Count=%d", &iFileMasks );

			if ( iFolders >= 0 )
			{
				break;
			}
			else
			{
				continue;
			}
		}
	}

	if ( iFolders   < 0 ) iFolders	 = 0;
	if ( iFileMasks < 0 ) iFileMasks = 0;

	//
	//	SEEK TO BEGIN
	//
	file.SeekToBegin();

	//
	//	SETUP ARRAYS
	//
	CFolder*	pFolders	= (0 == iFolders   ) ? NULL : new CFolder	[ iFolders	 ];
	CFileMask*	pFileMasks	= (0 == iFileMasks ) ? NULL : new CFileMask	[ iFileMasks ];

	//
	//	READ ENTRIES
	//
	int		iFolder		= 0;
	int		iFileMask	= 0;
	CString	strValue	;

	while ( TRUE == file.ReadString( strLine ) )
	{
		//
		//	FOLDER PATH
		//
		if ( strLine.Find( "Folder.Path" ) >= 0 )
		{
			::sscanf( strLine, "Folder.Path.%d=%s", &iFolder, strValue.GetBuffer( 2 * _MAX_PATH ) );	strValue.ReleaseBuffer();

			pFolders[ iFolder ].m_strPath = strValue;

			continue;
		}

		//
		//	FOLDER ENABLED
		//
		if ( strLine.Find( "Folder.Enabled" ) >= 0 )
		{
			::sscanf( strLine, "Folder.Enabled.%d=%s", &iFolder, strValue.GetBuffer( 2 * _MAX_PATH ) );	strValue.ReleaseBuffer();

			pFolders[ iFolder ].m_bEnabled = "true" == strValue ? TRUE : FALSE;

			continue;
		}

		//
		//	FOLDER RECURSIVE
		//
		if ( strLine.Find( "Folder.Recurse" ) >= 0 )
		{
			::sscanf( strLine, "Folder.Recurse.%d=%s", &iFolder, strValue.GetBuffer( 2 * _MAX_PATH ) );	strValue.ReleaseBuffer();

			pFolders[ iFolder ].m_bRecurse = "true" == strValue ? TRUE : FALSE;

			continue;
		}

		//
		//	FILE MAKS
		//
		if ( strLine.Find( "FileMask.Mask" ) >= 0 )
		{
			::sscanf( strLine, "FileMask.Mask.%d=%s", &iFileMask, strValue.GetBuffer( 2 * _MAX_PATH ) );	strValue.ReleaseBuffer();

			pFileMasks[ iFileMask ].m_strMask = strValue;

			continue;
		}

		//
		//	MASK ENABLED
		//
		if ( strLine.Find( "FileMask.Enabled" ) >= 0 )
		{
			::sscanf( strLine, "FileMask.Enabled.%d=%s", &iFileMask, strValue.GetBuffer( 2 * _MAX_PATH ) );	strValue.ReleaseBuffer();

			pFileMasks[ iFileMask ].m_bEnabled = "true" == strValue ? TRUE : FALSE;

			continue;
		}
	}

	//
	//	CLOSE FILE
	//
	file.Close();

	//
	//	CLEAR CONTROLS
	//
	this->m_ctrlListFolders	 .DeleteAllItems();
	this->m_ctrlListFileMasks.DeleteAllItems();

	//
	//	INSERT ARRAYS INTO CONTROLS
	//
	for ( iFolder = 0; iFolder < iFolders; iFolder++ )
	{
		this->InsertFolder( this->m_ctrlListFolders.GetItemCount(), pFolders[ iFolder ] );
	}

	for ( iFileMask = 0; iFileMask < iFileMasks; iFileMask++ )
	{
		this->InsertFileMask( this->m_ctrlListFileMasks.GetItemCount(), pFileMasks[ iFileMask ] );
	}

	//
	//	DELETE ARRAYS
	//
	delete [] pFolders	;
	delete [] pFileMasks;
}

//***************************************************************************************************
//**																				   UpdateControls
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Updates the controls
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::UpdateControls( void ) 
{
	this->m_ctrlListFolders  .DeleteAllItems();
	this->m_ctrlListFileMasks.DeleteAllItems();

	for ( int iFolder = 0; iFolder < this->m_arrFolders.GetSize(); iFolder++ )
	{
		this->InsertFolder( iFolder, this->m_arrFolders[ iFolder ] );
	}

	for ( int iFileMask = 0; iFileMask < this->m_arrFileMasks.GetSize(); iFileMask++ )
	{
		this->InsertFileMask( iFileMask, this->m_arrFileMasks[ iFileMask ] );
	}
}

//***************************************************************************************************
//**																				    UpdateMembers
//***************************************************************************************************
//**	@DOC		HELPERS
//**	@MFUNC		Updates the members
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::UpdateMembers( void ) 
{
	this->m_arrFolders  .RemoveAll();
	this->m_arrFileMasks.RemoveAll();

	CFolder folder;

	for ( int iFolder = 0; iFolder < this->m_ctrlListFolders.GetItemCount(); iFolder++ )
	{
		this->GetFolder( iFolder, folder );

		this->m_arrFolders.Add( folder );
	}

	CFileMask mask;

	for ( int iFileMask = 0; iFileMask < this->m_ctrlListFileMasks.GetItemCount(); iFileMask++ )
	{
		this->GetFileMask( iFileMask, mask );

		this->m_arrFileMasks.Add( mask );
	}
}

//
//---------------------------------------------------------------------------------------------------
//****************************************     VIRTUALS     *****************************************
//---------------------------------------------------------------------------------------------------
//

//***************************************************************************************************
//**																				   DoDataExchange
//***************************************************************************************************
//**	@DOC		VIRTUALS
//**	@MFUNC		Exchanges data between the dialog's members and its controls
//**	@PARM		[in/out] Pointer to data exchange context
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange( pDX );

	//{{AFX_DATA_MAP(CDialogFilters)
	DDX_Control( pDX, IDC_LIST_FOLDERS	, m_ctrlListFolders		);
	DDX_Control( pDX, IDC_LIST_FILES	, m_ctrlListFileMasks	);
	//}}AFX_DATA_MAP
}

//
//---------------------------------------------------------------------------------------------------
//****************************************     MESSAGES     *****************************************
//---------------------------------------------------------------------------------------------------
//

BEGIN_MESSAGE_MAP( CDialogFilters, CDialog )
	//{{AFX_MSG_MAP(CDialogFilters)
	ON_BN_CLICKED	(					IDC_EXPORT			, OnExport					)
	ON_BN_CLICKED	(					IDC_IMPORT			, OnImport					)
	ON_BN_CLICKED	(					IDC_ADD_FOLDER		, OnAddFolder				)
	ON_BN_CLICKED	(					IDC_ADD_FILE		, OnAddFile					)
	ON_BN_CLICKED	(					IDC_REMOVE_FOLDER	, OnRemoveFolder			)
	ON_BN_CLICKED	(					IDC_REMOVE_FILE		, OnRemoveFile				)
	ON_NOTIFY		( LVN_ENDLABELEDIT, IDC_LIST_FOLDERS	, OnEndLabelEditListFolders	)
	ON_NOTIFY		( LVN_ENDLABELEDIT, IDC_LIST_FILES		, OnEndLabelEditListFiles	)
	ON_NOTIFY		( LVN_ITEMACTIVATE, IDC_LIST_FOLDERS	, OnItemActivateListFolders	)
	ON_NOTIFY		( LVN_ITEMACTIVATE, IDC_LIST_FILES		, OnItemActivateListFiles	)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//***************************************************************************************************
//**																					 OnInitDialog
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		Called to initialize the dialog
//**	@END
//***************************************************************************************************
//inline
BOOL CDialogFilters::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	this->m_ctrlListFolders		.InsertColumn	 ( 0, "Path"	, LVCFMT_LEFT, 290, 0 );
	this->m_ctrlListFolders		.InsertColumn	 ( 1, "Recurse"	, LVCFMT_LEFT,  70, 1 );
	this->m_ctrlListFileMasks	.InsertColumn	 ( 0, "Mask"	, LVCFMT_LEFT, 300, 0 );

	this->m_ctrlListFolders		.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES );
	this->m_ctrlListFileMasks	.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES );

	this->UpdateControls();

	return TRUE;  
}

//***************************************************************************************************
//**																							 OnOK
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnOK() 
{
	this->UpdateMembers();

	CDialog::OnOK();
}

//***************************************************************************************************
//**																						 OnCancel 
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnCancel() 
{
	CDialog::OnCancel();
}

//***************************************************************************************************
//**																						 OnExport
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnExport() 
{
	//
	//	LOAD FILE SPECS
	//
	CString strFileSpec;
			strFileSpec.LoadString( IDS_TEXTFILES );

	//
	//	LET USER SELECT FILE
	//
	CFileDialog dlgBrowser( FALSE, "", "", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strFileSpec );

	if ( IDOK != dlgBrowser.DoModal() )
	{
		return;
	}

	//
	//	EXPORT
	//
	this->ExportFilters( dlgBrowser.GetPathName() );
}

//***************************************************************************************************
//**																						 OnImport
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnImport() 
{
	//
	//	LOAD FILE SPECS
	//
	CString strFileSpec;
			strFileSpec.LoadString( IDS_TEXTFILES );

	//
	//	LET USER SELECT FILE
	//
	CFileDialog dlgBrowser( TRUE, "", "", OFN_HIDEREADONLY, strFileSpec );

	if ( IDOK != dlgBrowser.DoModal() )
	{
		return;
	}

	//
	//	IMPORT
	//
	this->ImportFilters( dlgBrowser.GetPathName() );
}

//***************************************************************************************************
//**																					  OnAddFolder
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnAddFolder() 
{
	//
	//	ALLOW ONLY ONE EDIT AT A TIME
	//
	for ( int iFolder = 0; iFolder < this->m_ctrlListFolders.GetItemCount(); iFolder++ )
	{
		if ( "(double-click to edit)" == this->m_ctrlListFolders.GetItemText( iFolder, 0 ) )
		{
			return;
		}
	}

	//
	//	ADD EMPTY FOLDER
	//
	CFolder folder( "(double-click to edit)" );

	int iItem = this->InsertFolder( this->m_ctrlListFolders.GetItemCount(), folder );

	this->m_ctrlListFolders.EditLabel( 0 );
}

//***************************************************************************************************
//**																						OnAddFile 
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnAddFile() 
{
	//
	//	ALLOW ONLY ONE EDIT AT A TIME
	//
	for ( int iFileMask = 0; iFileMask < this->m_ctrlListFileMasks.GetItemCount(); iFileMask++ )
	{
		if ( "(click to edit)" == this->m_ctrlListFileMasks.GetItemText( iFileMask, 0 ) )
		{
			return;
		}
	}

	//
	//	ADD EMPTY MASK
	//
	CFileMask mask( "(click to edit)" );

	int iItem = this->InsertFileMask( this->m_ctrlListFileMasks.GetItemCount(), mask );

	this->m_ctrlListFileMasks.EditLabel( 0 );
}

//***************************************************************************************************
//**																				   OnRemoveFolder 
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnRemoveFolder() 
{
	POSITION pos = this->m_ctrlListFolders.GetFirstSelectedItemPosition();

	if ( NULL != pos )
	{
		int iItem = this->m_ctrlListFolders.GetNextSelectedItem( pos );

		this->m_ctrlListFolders.DeleteItem( iItem );

		this->OnRemoveFolder();
	}
}

//***************************************************************************************************
//**																					 OnRemoveFile 
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnRemoveFile() 
{
	POSITION pos = this->m_ctrlListFileMasks.GetFirstSelectedItemPosition();

	if ( NULL != pos )
	{
		int iItem = this->m_ctrlListFileMasks.GetNextSelectedItem( pos );

		this->m_ctrlListFileMasks.DeleteItem( iItem );

		this->OnRemoveFile();
	}
}

//***************************************************************************************************
//**																		OnItemActivateListFolders
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnItemActivateListFolders(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NMLISTVIEW* pNMListView = (NMLISTVIEW*)pNMHDR;

	*pResult = 0;

	//
	//	GET ITEM'S FOLDER
	//
	CFolder folder	;
	int		iItem	= pNMListView->iItem;

	this->GetFolder( iItem, folder );

	//
	//	SETUP FOLDER DIALOG
	//
	CDialogFolder dlgFolder;

	//
	//	EXCHANGE DATA TO DIALOG
	//
	dlgFolder.m_strPath		= "(double-click to edit)" == folder.m_strPath ? "" : folder.m_strPath;
	dlgFolder.m_bRecurse	= folder.m_bRecurse;

	//
	//	RUN DIALOG
	//
	if ( IDOK != dlgFolder.DoModal() )
	{
		return;
	}

	//
	//	EXCHANGE DATA FROM DIALOG
	//
	folder.m_strPath		= dlgFolder.m_strPath.IsEmpty() ? "(double-click to edit)" : dlgFolder.m_strPath;
	folder.m_bRecurse		= dlgFolder.m_bRecurse;

	//
	//	UPDATE LIST CONTROL
	//
	this->m_ctrlListFolders.SetItemText	( iItem, 0,	folder.m_strPath  );
	this->m_ctrlListFolders.SetItemText	( iItem, 1,	folder.m_bRecurse ? "Yes" : "No" );
}

//***************************************************************************************************
//**																		  OnItemActivateListFiles
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnItemActivateListFiles(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NMLISTVIEW* pNMListView = (NMLISTVIEW*)pNMHDR;
	
	*pResult = 0;
}

//***************************************************************************************************
//**																		  OnEndLabelEditListFiles
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnEndLabelEditListFiles(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NMLVDISPINFO* pNMListView = reinterpret_cast< NMLVDISPINFO* > (pNMHDR);

	*pResult = 0;

	if ( 0 != pNMListView->item.iSubItem )
	{
		return;
	}

	if ( NULL == this->m_ctrlListFileMasks.GetEditControl() )
	{
		return;
	}

	CString strText;

	this->m_ctrlListFileMasks.GetEditControl()->GetWindowText( strText );

	this->m_ctrlListFileMasks.SetItemText( pNMListView->item.iItem, 0, strText );
}

//***************************************************************************************************
//**																		OnEndLabelEditListFolders
//***************************************************************************************************
//**	@DOC		MESSAGES
//**	@MFUNC		
//**	@END
//***************************************************************************************************
//inline
void CDialogFilters::OnEndLabelEditListFolders(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NMLVDISPINFO* pNMListView = reinterpret_cast< NMLVDISPINFO* > (pNMHDR);
	
	*pResult = 0;

	if ( 0 != pNMListView->item.iSubItem )
	{
		return;
	}

	if ( NULL == this->m_ctrlListFolders.GetEditControl() )
	{
		return;
	}

	CString strText;

	this->m_ctrlListFolders.GetEditControl()->GetWindowText( strText );

	this->m_ctrlListFolders.SetItemText( pNMListView->item.iItem, 0, strText );
}


